package com.jy.project.controller;

import com.github.pagehelper.PageInfo;
import com.jy.project.dto.SignDTO;
import com.jy.project.dto.SignQueryDTO;
import com.jy.project.dto.ToDoTasksDTO;
import com.jy.project.ex.BizException;
import com.jy.project.service.ToDoTasksService;
import com.jy.project.util.ServiceResultUtils;
import com.jy.project.vo.SignVO;
import com.jy.project.vo.ToDoTasksVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/v1")
@CrossOrigin
@Slf4j
public class ToDoTasksController {
    @Autowired
    private ToDoTasksService toDoTasksService;
    /**
     *获取当前能审批单据
     */
    @RequestMapping("/toDoTasks/list")
    @ResponseBody
    public Object list(@RequestBody ToDoTasksDTO dto,Long userId) {
        dto.setUserId(userId);
        List<ToDoTasksVO> toDoTasksVOS = toDoTasksService.listToDoTasksVO(dto);
        return ServiceResultUtils.success(new PageInfo<>(toDoTasksVOS));
    }

    /**
     * 获取当前单据的加签
     */
    @RequestMapping("/toDoTasks/sign/list")
    @ResponseBody
    public Object listSign(@RequestBody SignQueryDTO dto,Long userId) {
        dto.setUserId(userId);
        List<SignVO> signVOS = toDoTasksService.listSignVO(dto);
        return ServiceResultUtils.success(signVOS);
    }

    /**
     * 获取当前单据的加签
     */
    @RequestMapping("/toDoTasks/sign/insert")
    @ResponseBody
    public Object insertSign(@RequestBody SignDTO dto,Long userId) {
        dto.setUserId(userId);
        boolean b = toDoTasksService.insertSign(dto);
        if (b){
            return ServiceResultUtils.success();
        }
        throw new BizException("加签失败");
    }
}
